import 'package:detect/utils/global.dart';
import 'package:flutter/material.dart';
import 'package:flutter_color_plugin/flutter_color_plugin.dart';

class RadioTile<T> extends StatelessWidget {
  final T value;
  final T? groupValue;
  final Widget? label;
  final double? size;
  final void Function(T value)? onCheck;

  const RadioTile({super.key, required this.value, this.groupValue, this.label, this.size, this.onCheck});

  @override
  Widget build(BuildContext context) {
    double size = this.size ?? Global.ds(16);
    List<Widget> widgets = [
      (groupValue == null ? (value is bool ? value as bool : false) : value == groupValue)
          ? Container(
              width: size,
              height: size,
              alignment: Alignment.center,
              decoration: BoxDecoration(color: ColorUtil.color("#366485"), borderRadius: BorderRadius.circular(size / 2)),
              child: Icon(Icons.done, color: Colors.white, size: size * .75),
            )
          : Container(
              width: size,
              height: size,
              decoration: BoxDecoration(border: Border.all(color: ColorUtil.color("#3B99CC")), borderRadius: BorderRadius.circular(size / 2)),
            ),
    ];
    if (label != null) {
      widgets.add(VerticalDivider(width: Global.ds(10), color: Colors.transparent));
      widgets.add(Flexible(child: FittedBox(fit: BoxFit.scaleDown, child: label)));
    }
    return GestureDetector(
      onTap: () => onCheck?.call(value),
      child: Row(mainAxisSize: MainAxisSize.min, children: widgets),
    );
  }
}
